//
//  HeadView.m
//  Topit
//
//  Created by dllo on 15/12/7.
//  Copyright © 2015年 YXY. All rights reserved.
//

#import "HeadView.h"

@implementation HeadView

- (void)dealloc {
    [_views release];
    [_images release];
    [_labels release];
    [_bio release];
    [_idImage release];
    [_idName release];
    [_ts release];
    [_fnum release];
    [_heart release];
    [_skipIamge release];
    [_background release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.views = [[UIView alloc] initWithFrame:self.bounds];
        [self addSubview:_views];
        [_views release];
        
        self.images = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width / 2 - 45, 44, 90, 90)];
        _images.contentMode = UIViewContentModeScaleAspectFill;
        _images.clipsToBounds = YES;
        _images.userInteractionEnabled = YES;
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fangda)];
        singleTap.numberOfTapsRequired = 1;
        [_views addSubview:_images];
        [_images addGestureRecognizer:singleTap];
        [_images release];
        
        self.labels = [[UILabel alloc] initWithFrame:CGRectMake(0, _images.bottom + 20, self.frame.size.width, 10)];
        _labels.textAlignment = 1;
        _labels.numberOfLines = 2;
        _labels.font = [UIFont systemFontOfSize:12];
        [_views addSubview:_labels];
        [_labels release];
        
        self.bio = [[UILabel alloc] initWithFrame:CGRectMake(0, _labels.bottom + 10, self.width, 100)];
        _bio.textAlignment = 1;
        _bio.numberOfLines = 0;
        _bio.font = [UIFont systemFontOfSize:10];
        _bio.textColor = [UIColor grayColor];
        [_views addSubview:_bio];
        [_bio release];
        
        self.idImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, self.frame.size.height - 70, 30, 30)];
        _idImage.layer.cornerRadius = 15;
        _idImage.clipsToBounds = YES;
        [_views addSubview:_idImage];
        [_idImage release];
        
        self.idName = [[UILabel alloc] initWithFrame:CGRectMake(_idImage.right + 5, _idImage.frame.origin.y + 2, 100, 10)];
        _idName.font = [UIFont systemFontOfSize:10];
        [_views addSubview:_idName];
        [_idName release];
        
        self.ts = [[UILabel alloc] initWithFrame:CGRectMake(_idName.origin.x, _idName.bottom + 5, 100, 10)];
        _ts.font = [UIFont systemFontOfSize:8];
        _ts.textColor = [UIColor grayColor];
        [_views addSubview:_ts];
        [_ts release];
        
        self.fnum = [[UILabel alloc] initWithFrame:CGRectMake(self.size.width - 80, _idImage.origin.y + 10, 70, 10)];
        _fnum.textColor = [UIColor orangeColor];
        _fnum.font = [UIFont systemFontOfSize:12];
        [_views addSubview:_fnum];
        [_fnum release];
        
        self.heart = [[UILabel alloc] initWithFrame:CGRectMake(_fnum.right, _idImage.origin.y - 2, 30, _idImage.frame.size.height)];
        [_views addSubview:_heart];
        [_heart release];
    }
    return self;
}

- (void)setSelectionModel:(YXYSelectionModel *)selection {
 
    [_images sd_setImageWithURL:[NSURL URLWithString:selection.icon[@"url"]]];
    [_images nightMode];
    _labels.text = selection.name;
    [_labels nightMode];
    _bio.text = selection.bio[@"txt"];
    [_bio nightMode];
    _ts.text = selection.ts;
    [_ts nightMode];
    
    _skipIamge = selection.icon[@"url"];
    YXYSelectionLowerModel *selectionLower = [selection.btnArray lastObject];
    [_idImage sd_setImageWithURL:selectionLower.icon[@"url"]];
    [_idImage nightMode];
    _idName.text = selectionLower.cont;
    [_idName nightMode];
    _fnum.text = [NSString stringWithFormat:@"%@%@", selection.fnum, @"人喜欢"];
    [_fnum nightMode];
}

- (void)fangda {
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, 200, 200)];
    [imgView sd_setImageWithURL:[NSURL URLWithString:_skipIamge]];
    [SJAvatarBrowser showImage:imgView];
}


@end
